import pkg_resources

# 你指定的依赖包（已去重）
required_packages = [
    'pydirectinput',
    'pywin32',  # 包含win32gui, win32ui, win32con
    'opencv-python',  # cv2
    'numpy',
    'ultralytics',  # YOLO
    'Pillow',  # PIL
    'onnxruntime',
    'joblib',
    'requests',
    'pyautogui',
]

# 生成requirements.txt
with open('../requirements.txt', 'w', encoding='utf-8') as f:
    for package in required_packages:
        try:
            version = pkg_resources.get_distribution(package).version
            f.write(f"{package}=={version}\n")
            print(f"已添加: {package}=={version}")
        except pkg_resources.DistributionNotFound:
            print(f"警告: 未安装 {package}")
            f.write(f"{package}\n")
        except Exception as e:
            print(f"获取 {package} 版本时出错: {e}")
            f.write(f"{package}\n")

print("\nrequirements.txt 生成完成")
